﻿using System;
using System.Diagnostics;
using CoreEx.Common.Logging;

namespace CoreEx.Common.Implementation.Logging
{
    /// <summary>
    /// The default <see cref="ILogger"/> that forwards log messages 
    /// to the <see cref="Trace"/> system.
    /// </summary>
    public class TraceLogAdapter : ILogger
    {
        /// <summary>
        /// Logs a debug message.
        /// </summary>
        /// <param name="message">The message to log.</param>
        public void LogDebug(object message)
        {                        
            Trace.WriteLine(string.Format("Severity: {0} Message {1}","DEBUG",message));
        }

        /// <summary>
        /// Logs a debug message.
        /// </summary>
        /// <param name="message">The message to log.</param>
        /// <param name="exception">An <see cref="Exception"/> to be logged with the message.</param>
        public void LogDebug(object message, Exception exception)
        {            
            Trace.WriteLine(string.Format("Severity: {0} Message; {1} Exception : {2}", "DEBUG", message, exception));
        }

        /// <summary>
        /// Logs an info message.
        /// </summary>
        /// <param name="message">The message to log.</param>
        public void LogInfo(object message)
        {
            Trace.WriteLine(string.Format("Severity: {0} Message; {1}", "DEBUG", message));            
        }

        /// <summary>
        /// Logs an info message.
        /// </summary>
        /// <param name="message">The message to log.</param>
        /// <param name="exception">An <see cref="Exception"/> to be logged with the message.</param>
        public void LogInfo(object message, Exception exception)
        {        
            Trace.WriteLine(string.Format("Severity: {0} Message; {1} Exception : {2}", "INFO", message, exception));
        }

        /// <summary>
        /// Logs a warning message.
        /// </summary>
        /// <param name="message">The message to log.</param>
        public void LogWarning(object message)
        {
            Trace.WriteLine(string.Format("Severity: {0} Message; {1}", "WARNING", message));            
        }

        /// <summary>
        /// Logs a warning message.
        /// </summary>
        /// <param name="message">The message to log.</param>
        /// <param name="exception">An <see cref="Exception"/> to be logged with the message.</param>
        public void LogWarning(object message, Exception exception)
        {            
            Trace.WriteLine(string.Format("Severity: {0} Message; {1} Exception : {2}", "WARNING", message, exception));
        }

        /// <summary>
        /// Logs an error message.
        /// </summary>
        /// <param name="message">The message to log.</param>
        public void LogError(object message)
        {
            Trace.WriteLine(string.Format("Severity: {0} Message; {1}", "ERROR", message));            
        }

        /// <summary>
        /// Logs an error message.
        /// </summary>
        /// <param name="message">The message to log.</param>
        /// <param name="exception">An <see cref="Exception"/> to be logged with the message.</param>
        public void LogError(object message, Exception exception)
        {            
            Trace.WriteLine(string.Format("Severity: {0} Message; {1} Exception : {2}", "ERROR", message, exception));
        }

        /// <summary>
        /// Logs a fatal message.
        /// </summary>
        /// <param name="message">The message to log.</param>
        public void LogFatal(object message)
        {
            Trace.WriteLine(string.Format("Severity: {0} Message; {1}", "FATAL", message));            
        }

        /// <summary>
        /// Logs a fatal message.
        /// </summary>
        /// <param name="message">The message to log.</param>
        /// <param name="exception">An <see cref="Exception"/> to be logged with the message.</param>
        public void LogFatal(object message, Exception exception)
        {
            Trace.WriteLine(string.Format("Severity: {0} Message; {1} Exception : {2}", "FATAL", message, exception));
        }
    }
}
